<template>
	<view class="content">
		<view class="all">
			<view class="content_1">
				绑定手机号
			</view>
			<view class="content_2">
				手机号
			</view>
			<view class="content_3">
				<input type="text" v-model="form.mobile" placeholder="请输入手机号" />
			</view>
			<view class="content_2">
				验证码
			</view>
			<view class="content_3">
				<input type="text" v-model="form.captcha" placeholder="请输入验证码" />
				<text @click="yzm" class="yzm">
					<text v-if="cl">{{number+'s'}}</text>
					获取验证码</text>
			</view>
			<text class="content_4" @click="submit">确认</text>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				form: {
					mobile: '',
					captcha: '',
				},
				password: true,
				cl: false,
				number: 60,
				token: ''
			};
		},
		onLoad(a) {
			this.token = a.token
			console.log(this.token);
		},
		methods: {
			countdown() {
				if (this.number == 0) {
					this.cl = false,
						this.number = 60;
					return false;
				} else {
					this.number--;
				}
				setTimeout(() => {
					this.countdown();
				}, 1000);
			},
			// 手机验证码
			yzm() {
				if (this.cl) {
					this.$toast(this.number + 's后点击')
					return
				}
				if (!this.form.mobile) {
					this.$toast('请输入手机号')
					return
				}
				this.api('Sms/send', {
					mobile: this.form.mobile,
					event: 'mobilelogin'
				}).then(res => {
					this.cl = true
					this.countdown()
				})

			},
			//注册
			submit() {
				if (!this.form.mobile) {
					this.$toast('请输入手机号')
					return
				}
				if (!this.form.captcha) {
					this.$toast('请输入验证码')
					return
				}
				uni.request({
					url: this.$http + 'api/' + 'User/bindMobile',
					method: "POST",
					header: {
						"content-type": 'application/x-www-form-urlencoded',
						token: this.token
					},
					data: {
						...this.form
					},
					success: (res) => {
						switch (res.data.code) {
							case 1:
								this.$toast('绑定成功')
								uni.setStorageSync('token', this.token)
								setTimeout(() => {
									uni.navigateBack({

									})

								}, 600)

								break;
							case 0:
								//提交订单购买库存不足跳回商城
								this.$toast(res.data.msg, 0)
								break;
							case 401: //错误码token
								uni.showToast({
									title: '登录过期!重新登录',
									icon: "error",
								});
								break;
							default:
								break;
						}
					}
				})

				// this.api('User/bindMobile', this.form).then(res => {
				// 	this.$toast(res.msg)
				// 	uni.setStorageSync('token', this.token)
				// 	uni.navigateBack({

				// 	})
				// })
			},
		}
	}
</script>

<style lang="scss">
	.all {
		padding: 25rpx;
	}

	.wxs {
		text-align: center;
		margin-top: 20rpx;
	}

	.wx {
		width: 81rpx;
		height: 81rpx;
	}

	.content_1 {
		margin-top: 200rpx;
		margin-bottom: 100rpx;
		font-size: 50rpx;
		font-family: OPPOSans;
		font-weight: 500;
		color: #181818;
	}

	.content_2 {
		margin-top: 50rpx;
		font-size: 32rpx;
		font-family: OPPOSans;
		font-weight: 600;
		color: #181818;
	}

	//输入框样式
	.content_3 {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 10rpx auto;
		height: 80rpx;
		background: #FFFFFF;
		border: 1rpx solid #E1E1E1;
		padding: 0 25rpx 0 25rpx;
		border-radius: 16rpx;

		::v-deep .input-placeholder {
			font-size: 24rpx;
			font-family: OPPOSans;
			font-weight: 400;
			color: #999999;
		}

		.yzm {
			display: inline-block;
			padding: 0 10rpx 0 10rpx;
			height: 60rpx;
			background-color: rgba($color: #E1E1E1, $alpha: 0.5);
			line-height: 60rpx;
			text-align: center;
			border-radius: 16rpx;
			font-size: 22rpx;
			font-family: OPPOSans;
			font-weight: 400;
			color: #333333;
			;
		}

		image {
			width: 32rpx;
			height: 14rpx;
		}

		input {
			width: 72%;
		}
	}

	.content_4 {
		margin-top: 130rpx;
		height: 80rpx;
		background: #FF1B1B;
		text-align: center;
		line-height: 80rpx;
		border-radius: 40rpx;
		display: inline-block;
		width: 100%;
		font-size: 30rpx;
		font-family: OPPOSans;
		font-weight: 500;
		color: #FFFFFF;
	}

	.content_5 {
		margin-top: 30rpx;
		text-align: center;

		text:nth-of-type(1) {
			font-size: 30rpx;
			font-family: OPPOSans;
			font-weight: 400;
			color: #666666;
		}

		text:nth-of-type(2) {
			display: inline-block;
			width: 2rpx;
			height: 28rpx;
			background: #D2D2D2;
			margin: 0 20rpx 0 20rpx;

		}

		text:nth-of-type(3) {
			font-size: 30rpx;
			font-family: OPPOSans;
			font-weight: 400;
			color: #666666;
		}
	}

	.content_6 {
		margin-top: 130rpx;
	}
</style>
